Bayesian Drone Weaver — User Guide
Algorithmic drone composition: Bayesian classification of audio clips into gesture types, intelligent timeline construction, and overlapping assembly for continuous ambient textures.
What this does
This script implements Bayesian Drone Weaver — an algorithmic composition system that analyzes audio clips, classifies them into musical gesture types using Bayesian inference, constructs intelligent timelines, and weaves them into continuous ambient drone textures. Process: (1) Audio analysis: Extract intensity, spectral, harmonic, and temporal features from each clip. (2) Bayesian classification: Compute posterior probabilities for five gesture hypotheses (Sustain, Swell, Tension, Air, Pulse). (3) Timeline construction: Build narrative arc (intro→development→climax→resolution) by matching clip characteristics to phase-based targets. (4) Overlap assembly: Mix clips with calculated overlaps and crossfades to create seamless drone. Result: Algorithmically composed ambient piece from raw audio materials.
Key Features:
- 5 Gesture Types — Bayesian classification into Sustain, Swell, Tension, Air, Pulse
- 4 Built-in Presets — Ambient, Cinematic, Meditative, Textural composition styles
- Narrative Timeline — Intelligent arc construction (intro→climax→resolution)
- Adaptive Overlaps — Flow-based overlap calculation for seamless transitions
- Feature Extraction — Intensity, brightness, harmonicity, voicing analysis
- Visual Timeline — Color-coded visualization of composition structure
Technical Implementation: (1) File processing: Load WAV/AIFF/FLAC files, convert to mono, resample to 44.1kHz, validate duration (0.1–30s). (2) Feature extraction: Intensity (mean, std, motion), spectral brightness, harmonicity, voicing fraction. (3) Bayesian classification: Compute log-likelihoods for each gesture hypothesis, apply uniform prior (0.2), normalize to posterior probabilities. (4) Macro-feature derivation: Compute flow, growth, edge, space, soften from posteriors. (5) Timeline construction: Four-phase narrative arc with phase-specific targets, select clips minimizing Euclidean distance to targets. (6) Overlap calculation: Flow/space dependent overlaps with preset scaling. (7) Assembly: Apply fades (in/out), optional intensity scaling, mix into final drone. (8) Visualization: Draw timeline with color-coded gesture types.
Quick start
- Prepare a folder with audio clips (WAV/AIFF/FLAC, 0.1–30s duration).
- In Praat, run
Bayesian_Drone_Weaver.praat. - Choose Preset: Ambient, Cinematic, Meditative, Textural, or Custom.
- Set Max_clips (maximum clips to use, default 30).
- Adjust Overlap_factor (1.0 = default, >1 = more overlap, <1 = less).
- Enable Draw_visualization for timeline visualization.
- Click OK, select your folder of audio clips.
- Script analyzes clips, classifies gestures, builds timeline, outputs drone.
BayesianDrone_[Preset] appears in Objects window.
Bayesian Classification Theory
The Five Gesture Hypotheses
🎵 Gesture Taxonomy
Five mutually exclusive hypotheses:
- Sustain: Stable, steady-state, minimal intensity variation
- Swell: Crescendo/decrescendo, intensity motion > 0
- Tension: Bright, inharmonic, high intensity variance
- Air: Quiet, noisy/breathy, low harmonicity
- Pulse: Rhythmic, percussive, intensity variations
Each clip assigned posterior probability for each hypothesis
Feature Extraction
Features computed per clip:
Bayesian Inference Pipeline
📊 From Features to Probabilities
Step 1: Log-Likelihood Calculation
For each hypothesis h, compute log-likelihood L(h|features):
Step 2: Prior Application
Uniform prior: P(h) = 0.2 for all h
Log-posterior: log P(h|data) = L(h|data) + log P(h)
Step 3: Normalization
Exponentiate, normalize to sum=1 → posterior probabilities
Macro-Feature Derivation
From posteriors to compositional parameters:
Timeline Construction Algorithm
📈 Narrative Arc Generation
Four-phase structure:
| Phase | Flow | Growth | Edge | Space |
|---|---|---|---|---|
| Intro (0–25%) | 0.85 | 0.2 | 0.15 | 0.8 |
| Development (25–60%) | 0.75 | 0.7 | 0.4 | 0.5 |
| Climax (60–80%) | 0.5 | 0.4 | 0.75 | 0.3 |
| Resolution (80–100%) | 0.95 | 0.1 | 0.2 | 0.9 |
Clip selection: For each timeline position, find unused clip minimizing:
distance = √[(flow-target_flow)² + (growth-target_growth)² + (edge-target_edge)² + (space-target_space)²]
Continuity bonus: Prefer clips similar to previous in flow/edge
Overlap Calculation
Dynamic overlap based on flow and space:
Fade Application
Adaptive fade durations:
Composition Presets
Preset 1: Ambient
🌌 Slow Evolution
Parameters: max_clips=20, overlap_factor=1.2
Character: Gradual changes, long overlaps, smooth transitions
Timeline: Extended intro/resolution, gentle climax
Best for: Background ambiance, meditation, sleep music
Preset 2: Cinematic
🎬 Dramatic Arc
Parameters: max_clips=30, overlap_factor=0.8
Character: Clear narrative structure, stronger contrasts
Timeline: Pronounced climax, dynamic development
Best for: Film scoring, dramatic contexts, emotional arcs
Preset 3: Meditative
🧘 Sustained Focus
Parameters: max_clips=15, overlap_factor=1.5
Character: Minimal change, maximal overlap, stable
Timeline: Flat structure, subtle variations
Best for: Deep meditation, trance states, sustained attention
Preset 4: Textural
🎨 Varied Palette
Parameters: max_clips=40, overlap_factor=0.6
Character: Many short clips, less overlap, rapid changes
Timeline: Complex structure, many transitions
Best for: Experimental music, sound art, granular textures
Preset 5: Custom
🔧 User-Defined
Parameters: User specifies max_clips, overlap_factor
Character: Tailored to specific needs
Flexibility: Full control over density and structure
Best for: Advanced users, specific project requirements
Parameters & Features
User Parameters
| Parameter | Type | Default | Range | Description |
|---|---|---|---|---|
| Preset | option | Ambient | 1-5 | Composition style preset |
| Max_clips | positive | 30 | 3-100 | Maximum clips to use from folder |
| Overlap_factor | positive | 1.0 | 0.1-3.0 | Multiplier for overlap calculations |
| Draw_visualization | boolean | yes | yes/no | Draw timeline visualization |
Internal Constants
| Constant | Value | Description |
|---|---|---|
| target_sr | 44100 Hz | Target sampling rate |
| min_clips | 3 | Minimum clips required |
| intensity_floor | 40 dB | Minimum intensity for analysis |
| pitch_floor | 75 Hz | Minimum pitch for analysis |
| pitch_ceiling | 600 Hz | Maximum pitch for analysis |
| n_hypotheses | 5 | Number of gesture types |
Output Features
| Feature | Type | Range | Description |
|---|---|---|---|
| clip_class | integer | 1-5 | Dominant gesture type (1=Sustain, etc.) |
| clip_post_[1-5] | probability | [0,1] | Posterior probability for each gesture |
| clip_flow | continuous | [0,1] | Flow characteristic (high = smooth) |
| clip_growth | continuous | [0,1] | Growth potential (high = swells) |
| clip_edge | continuous | [0,0.85] | Edge/brightness (high = tense) |
| clip_space | continuous | [0,1] | Spatial quality (high = airy) |
| clip_soften | continuous | [0,1] | Softening factor (high = pulsed) |
Complete Workflow
Step-by-Step Processing
🔄 Processing Pipeline
- Folder selection: User selects folder with audio clips
- File scanning: Scan for WAV, AIFF, FLAC files
- Clip loading: Load up to Max_clips files
- Preprocessing: Convert to mono, resample to 44.1kHz
- Feature extraction: Intensity, spectral, harmonic features
- Bayesian classification: Compute gesture probabilities
- Macro-feature computation: Derive flow, growth, edge, space, soften
- Timeline construction: Build narrative arc, select clips
- Overlap calculation: Compute overlap between segments
- Assembly: Apply fades, mix clips into final drone
- Normalization: Scale peak to 0.95
- Visualization: Draw timeline (if enabled)
- Cleanup: Remove temporary objects
Input Requirements
- Formats: .wav, .aiff, .flac
- Duration: 0.1–30 seconds (optimal: 3–10s)
- Channels: Mono or stereo (converted to mono)
- Sampling rate: Any (resampled to 44.1kHz)
- Content: Any audio material (tonal, noisy, percussive, etc.)
- Quantity: Minimum 3 clips, recommended 10+ for good selection
Output Results
- Format: Mono, 44.1kHz, 32-bit floating point
- Duration: Variable (depends on clips and overlaps)
- Naming:
BayesianDrone_[PresetName] - Peak level: Normalized to 0.95 (-0.4 dBFS)
- Structure: Four-phase narrative arc
- Transitions: Adaptive fades and overlaps
Visualization Output
- Top: Title with preset name
- Main plot: Timeline with color-coded segments
- Colors: Blue=Sustain, Green=Swell, Red=Tension, Purple=Air, Orange=Pulse
- Labels: Clip indices within segments
- Axes: Time (seconds) vs Segment number
- Legend: Color-key for gesture types
Useful for understanding composition structure and clip usage
Advanced Usage Tips
- Curate input clips: Pre-select clips with desired characteristics
- Mix clip types: Combine tonal, noisy, percussive materials
- Control density: Use Overlap_factor: low = sparse, high = dense
- Scale duration: Adjust Max_clips for longer/shorter output
- Preset blending: Run multiple times with different presets, layer results
- Post-processing: Apply additional effects (reverb, EQ, modulation)
- Batch processing: Process multiple folders, compare results
Troubleshooting
Cause: Folder contains <3 valid audio files
Solution: Add more audio files, check formats/extensions
Cause: Clip durations extreme, overlap calculations unusual
Solution: Use more consistent clip durations (2-10s), adjust Overlap_factor
Cause: Overlap_factor too low, or flow/space very low
Solution: Increase Overlap_factor, use clips with higher flow
Cause: Features not capturing intended characteristics
Solution: Pre-process clips (normalize, filter), or modify likelihood formulas
Mathematical Foundation
📐 Bayesian Inference Details
Full probability model:
Note: Log-likelihoods use quadratic/linear approximations of true probability distributions. Parameters tuned empirically.